package com.atguigu.flink.datastreamapi.transform;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created by Smexy on 2022/12/13
 *
 *  并集。
 *          同流合污。
 *              流中元素的类型相同，才能将多个流合并为一个流。
 */
public class Demo5_Union
{
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);


        DataStreamSource<Integer> streamSource1 = env.fromElements(1, 2, 3, 4, 5, 6, 7);
        DataStreamSource<Integer> streamSource2 = env.fromElements(1, 2, 3, 4, 5, 6, 7);
        DataStreamSource<Integer> streamSource3 = env.fromElements(1, 2, 3, 4, 5, 6, 7);
        DataStreamSource<String> streamSource4 = env.fromElements("a","b");

       //合并为1个流
        DataStream<Integer> result = streamSource1.union(streamSource2,streamSource3);

        result.print();


        env.execute();

    }
}
